package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.CouponProfitRecordMapperExt;
import com.lzy.product.dtos.CouponProfitRecordDto;
import com.lzy.product.entity.CouponProfitRecord;
import com.lzy.product.service.CouponProfitRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * 卡券宝收益记录服务
 * Created by WIN7 on 2017/12/29.
 */
@Component
public class CouponProfitRecordServiceImpl implements CouponProfitRecordService {

    @Autowired
    private CouponProfitRecordMapperExt couponProfitRecordMapperExt;

    @Override
    public Long insert(CouponProfitRecordDto dto) {
        CouponProfitRecord record = DozerUtils.map(dto, CouponProfitRecord.class);
        return couponProfitRecordMapperExt.insertSelective(record) > 0 ? record.getId() : 0;
    }

    @Override
    public Boolean update(CouponProfitRecordDto dto) {
        return couponProfitRecordMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, CouponProfitRecord.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return null;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public CouponProfitRecordDto findById(Long id) {
        return DozerUtils.map(couponProfitRecordMapperExt.selectByPrimaryKey(id), CouponProfitRecordDto.class);
    }

    @Override
    public List<CouponProfitRecordDto> query(CouponProfitRecordDto dto) {
        return null;
    }

    @Override
    public List<CouponProfitRecordDto> queryLimitedList() {
        return couponProfitRecordMapperExt.queryLimitedList();
    }

    @Override
    public PageInfo<CouponProfitRecordDto> selectList(Pager pager, CouponProfitRecordDto paramDto) {
        if (pager != null) {
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        }
        List<CouponProfitRecordDto> list = couponProfitRecordMapperExt.selectList(paramDto);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<CouponProfitRecordDto> selectListByType(Pager pager, Long memberId, String type, Integer status) {
        if (pager != null) {
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        }
        List<CouponProfitRecordDto> list = couponProfitRecordMapperExt.selectListByType(memberId, type, status);
        return new PageInfo<>(list);
    }

    @Override
    public List<CouponProfitRecordDto> queryLimitedListByCommision() {
        return couponProfitRecordMapperExt.queryLimitedListByCommision();
    }

    @Override
    public BigDecimal limitMoney(Long memberId) {
        BigDecimal limitMoney = couponProfitRecordMapperExt.limitMoney(memberId);
        return limitMoney == null ? new BigDecimal(0) : limitMoney;
    }

    @Override
    public BigDecimal availableMoney(Long memberId) {
        BigDecimal availableMoney = couponProfitRecordMapperExt.availableMoney(memberId);
        return availableMoney == null ? new BigDecimal(0) : availableMoney;
    }


}
